package logic

import (
	"api/model/mysql"
	"context"

	"srv/dev"
	"srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListLogic {
	return &ListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ListLogic) List(in *dev.ListRequest) (*dev.ListResponse, error) {
	// todo: add your logic here and delete this line

	var house []mysql.Houses

	mysql.DB.Find(&house)

	var lists []*dev.List

	for _, m := range house {
		list := dev.List{
			Name:    m.Name,
			Address: m.Address,
			Typed:   m.Typed,
			Area:    int64(m.Area),
			Floor:   int64(m.Floor),
			Price:   float32(m.Price),
			Id:      int64(m.ID),
		}
		lists = append(lists, &list)
	}

	return &dev.ListResponse{
		List: lists,
	}, nil
}
